<script type="text/javascript">
/**
 * ------------------------------------------------------
 * 发布页面，需要避免重复加载
 * ------------------------------------------------------
 */
$(function(){
	var editorOption = {
			toolbars:[['fullscreen','source', '|', 'undo', 'redo', '|',
		                'bold', 'italic', 'underline','removeformat', 'formatmatch', 'autotypeset','|', 'forecolor', 'backcolor', '|',
		                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
		             	'fontfamily', 'fontsize', '|',
		                'indent', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
		                'link', 'unlink', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
		                'insertimage', 'emotion', 'insertvideo', 'music','attachment', 'map', 'template', '|',
		                'horizontal', 'spechars', '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 
		                'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 
		                'splittocells', 'splittorows', 'splittocols', 'charts', '|',
		                'preview', 'searchreplace', 'help']],
	      	wordCount : true,
	        textarea : "post_new_text",
	        autoHeightEnabled:false,
	        elementPathEnabled:false,
	        // focus:true,
	      	emotionLocalization:true,
	        pasteplain:false,
	        initialFrameHeight:370,
	        initialFrameWidth:840
	        // readonly:true
	        // contextMenu:[]
    };
	var new_editor = new baidu.editor.ui.Editor(editorOption);
	new_editor.render("post_new_text");
    $("#post_new_title").focus();
    //提交
    $("#post_new_submit").button().click(function(){
    	var title=$("#post_new_title").val();
		//var module=$("#post_new_module").val()
		var module=$(".modules_select:last").val();
		var content=new_editor.getContent();
		if(title.length==0){
			showTip($("#post_new_title"),"请输入内容标题！");
			return;
		}
		hideTip($("#post_new_title"));
		if(!new_editor.hasContents()){
			showTip($("#post_new_text"),"请输入内容正文！");
			return;
		}
		hideTip($("#post_new_text"));
		artConfirm("您确定发布吗？",function(){
			$("#post_new_submit").button("disable");
			$.post(BASE+"/admin/content/post_new",{'module':module,'title':title,'content':content},function(e){
				if(e.status==1){
					artSuccess("发布成功！",0,function(){
						//location.reload();
						reset();
					});
				}else{
					artError(e.info);
				}
				$("#post_new_submit").button("enable");
			},"json")
		},function(){
			return;
		})
	})
	function reset(){
    	$("#post_new_title").val("");
		hideTip($("#post_new_title"));
		hideTip($("#post_new_text"));
		//$("#post_new_module option:first").prop("selected", 'selected');
		$(".modules_select:first").prop("selected", 'selected');
		new_editor.execCommand("cleardoc");
    }
	//重置
	$("#post_new_reset").button().click(function(){
		artConfirm("您确定重置所有内容吗？",function(){
			reset();
		},function(){
			return;
		})
	})
})
</script>

<div id="show_post_new" class="main" width="850">
	<div class="main_left">
		<div class="title_container">
			<label><span class="title_label">{$Think.lang.CONTENT_TITLE}</span><span><input type="text" name="title" maxlength="50" id="post_new_title"></span></label>
		</div>
		<div class="title_container">
				<span class="title_label">{$Think.lang.BELONG_MODULE}</span>
				<include file="module_select"/>
				<!-- 
				<span>
					<select id="post_new_module">
						<foreach name="module" item="m">
							<option value="{$m.id}">{$m.name}</option>
						</foreach>
					</select>
				</span> -->
		</div>
		<div class="text_container">
			<!-- Ueditor -->
			<div id="post_new_text"></div>
		</div>
	</div>
	<div class="main_right">
		{$Think.lang.TIP_H3}
		{$Think.lang.POST_NEW_TIP}
	</div>
	<div class="post_btns">
		<button id="post_new_submit" >{$Think.lang.POST}</button>
		<button id="post_new_reset" >{$Think.lang.RESET}</button>
	</div>
</div>